/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package wads.app;

import wads.drawing.node.GateNode;
import java.awt.Frame;
import java.awt.Rectangle;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JRadioButton;

/**
 *
 * @author Nattasan W.
 */
public final class GateNodeDialog extends BaseWADDialog {
  
  private JRadioButton andGate = new JRadioButton("AND");
  private JRadioButton orGate = new JRadioButton("OR");
  private JRadioButton xorGate = new JRadioButton("XOR");
  private JRadioButton xoreGate = new JRadioButton("XOREVENT");
  private JRadioButton complexGate = new JRadioButton("COMPLEX");
  private ButtonGroup gateGroup = new ButtonGroup();
  
  private GateNode gate;

  public GateNodeDialog(Frame parent, GateNode owner) {
    super(parent, owner);
    this.gate = owner;
    
    this.setTitle("Choose gate type");
    
//    properties = gate.getGateProp();
    
    try {
      jbInit();
    }
    catch(Exception e) { e.printStackTrace(); }
  }

  @Override
  public void initDisplay() {
//    String gprop = properties.getProperty("GateType", "");
    int gprop = gate.getGateType();
    
    if(gprop == GateNode.AND) {
      andGate.setSelected(true);
    }
    else if(gprop == GateNode.OR) {
      orGate.setSelected(true);
    }
    else if(gprop == GateNode.XOR) {
      xorGate.setSelected(true);
    }
    else {
      System.err.println("Type not defined.");
    }
  }

  @Override
  public void saveProperties() {
    if(andGate.isSelected()) {
      gate.setGateType(GateNode.AND);
      gate.setGateIconImage(new ImageIcon("images/and32.png"));
    }
    else if(orGate.isSelected()) {
      gate.setGateType(GateNode.OR);
      gate.setGateIconImage(new ImageIcon("images/or32.png"));
    }
    else if(xorGate.isSelected()) {
      gate.setGateType(GateNode.XOR);
      gate.setGateIconImage(new ImageIcon("images/xor32.png"));
    }
    else {
      System.err.println("Gate Type not defined yet.");
      gate.setGateIconImage(new ImageIcon("images/notdefine32.png"));
    }
  }

  private void jbInit() throws Exception {
    this.getContentPane().setLayout(null);
    gateGroup.add(andGate);
    gateGroup.add(orGate);
    gateGroup.add(xorGate);
    gateGroup.add(xoreGate);
    gateGroup.add(complexGate);
    
    andGate.setBounds(new Rectangle(40, 30, 60, 25));
    orGate.setBounds(new Rectangle(40, 65, 60, 25));
    xorGate.setBounds(new Rectangle(40, 100, 60, 25));
    xoreGate.setBounds(new Rectangle(40, 135, 60, 25));
    complexGate.setBounds(new Rectangle(40, 170, 60, 25));
    
    this.getContentPane().add(andGate, null);
    //this.getContentPane().add(orGate, null);
    this.getContentPane().add(xorGate, null);
    //this.getContentPane().add(xoreGate, null);
    //this.getContentPane().add(complexGate, null);
    
    this.setSize(400, 300);
    this.setOptionButtonsPanelLocation(300);
  }

}
